﻿@inherits UmbracoTemplatePage

@{
    int pageIndex = 1, pageSize = 20, pageCount = 0, pageLimit = 10;
    int count = 0;

    string param = string.Empty;
    foreach (var key in Request.QueryString.Keys)
    {
        if (!key.ToString().Equals("page"))
        {
            param += "&" + key + "=" + Request.QueryString[key.ToString()];
        }
    }

    pageIndex = UtilTool.ConvertPageIndex(Request.QueryString["page"]);
    if (ViewData["count"] != null)
    {
        count = UtilTool.ConvertNumber(ViewData["count"].ToString(), 0);
    }
    if (ViewData["pageSize"] != null)
    {
        pageSize = UtilTool.ConvertNumber(ViewData["pageSize"].ToString(), 0);
    }
    if (ViewData["pageLimit"] != null)
    {
        pageLimit = UtilTool.ConvertNumber(ViewData["pageLimit"].ToString(), 10);
    }

    if (count % pageSize == 0)
    {
        pageCount = count / pageSize;
    }
    else
    {
        pageCount = (count - count % pageSize) / pageSize + 1;
    }
}

<div class="pagination-container">
    <nav aria-label="Page navigation">
        <ul class="pagination">
            @if (pageIndex == 1)
            {
                <li class="disabled">
                    <a href="javascript:;" aria-label="上一页">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            }
            else
            {
                <li>
                    <a href="@(Model.Content.Url + "?page=" + (pageIndex - 1) + param)" aria-label="上一页">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            }

            @if (pageCount < pageLimit)
            {
                for (var i = 1; i < pageCount + 1; i++)
                {
                    if (i == pageIndex)
                    {
                        <li class="active"><a href="javascript:;">@i</a></li>
                    }
                    else
                    {
                        <li><a href="@(Model.Content.Url + "?page=" + (i) + param)">@i</a></li>
                    }
                }
            }

            

            @if (pageIndex == pageCount)
            {
                <li class="disabled">
                    <a href="javascript:;" aria-label="下一页">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            }
            else
            {
                <li>
                    <a href="@(Model.Content.Url + "?page=" + (pageIndex + 1) + param)" aria-label="下一页">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            }
        </ul>
    </nav>
</div>
